package org.friping.mytool.views.picker;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.widget.EditText;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.friping.mytool.R;
import org.friping.mytool.helper.Constants;

@EActivity(R.layout.p_text)
public class PickerTextActivity extends PickerActivity {

    @ViewById
    EditText valueText;

    @AfterViews
    public void afterView(){
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        // render title
        if(title != null){
            actionBar.setTitle(title);
        }else{
            if(label != null){
                actionBar.setTitle("更改"+label);
            }
        }

        // render value
        value = value == null ? "" : value;
        valueText.setText(value.toString());
        // render hint
        valueText.setHint("请输入"+label);

        valueText.setSelection(valueText.getText().toString().trim().length());
    }

    @Click(R.id.btnSave)
    public void save(){
        String value = valueText.getText().toString();
        Intent intent=new Intent();
        intent.putExtra("name", name);
        intent.putExtra("value", value);
        setResult(Constants.PICKER_TEXT_RESULT_CODE,intent);
        finish();
    }

}
